package com.whyx.project.openapi.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.whyx.project.openapi.Impl.DistributeRepImpl;
import com.whyx.project.openapi.config.GtApiConfig;
import com.whyx.project.openapi.config.NettyClientConfig;
import com.whyx.project.openapi.map.MapUtil;
import com.whyx.project.openapi.util.R;
import com.common.utils.SnowFlakeIDGenerator;
import com.whyx.project.openapi.business.*;
import com.whyx.project.openapi.config.KafkaProducerConfig;
//import com.whyx.project.user.service.RedisService;
import exsun.jt808.data.base.StatusResult;

import exsun.jt808.data.config.jt808.Jt808DistributeMsgTopic;
import exsun.jt808.data.config.jt808.Jt808MsgIdTopicDic;
import exsun.jt808.data.distribute_data.DistributeEntity;
import exsun.jt808.data.distribute_data.jt1078.RealtimeMediaUploadReq;
import exsun.jt808.data.distribute_data.jt808.QueryAreaOrLineData;
import exsun.jt808.data.distribute_data.jt808.QueryServerTimeResponse;
import exsun.jt808.data.distribute_data.jt808.TakePhotoRightAway;
import exsun.jt808.data.distribute_data.jt808.Text;
import exsun.jt808.data.enume.OrderSendStatus;
import exsun.jt808.data.jt809_data.BasicVehicleInfo;
import exsun.jt808.data.jt809_data.PushJT809Data;
import exsun.jt808.data.jt809_data.SendBaseEntity;
import exsun.jt808.data.jt809_data.alarm.main.UpWarnMsgInfoEX;
import exsun.jt808.data.jt809_data.alarm.main.UpWarnMsgOperationInfoEx;
import exsun.jt808.data.jt809_data.vehicledynamic.main.UpExgMsgRegister;
import exsun.jt808.data.jt809_data.vehicledynamic.main.UpExgMsgSafetyTerminal;
import exsun.jt808.data.util.GsonUtils;
import exsun.jt808.data.util.HttpUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.json.JSONString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.text.SimpleDateFormat;


@RestController
@Api(description = "kafka指令下发API")
public class KafkaApiController {

    @Autowired
    GtApiConfig gtApiConfig;


    private final static Logger logger = LoggerFactory.getLogger(KafkaApiController.class);

    public static final String TOPIC_DISTRIBUTE_DATA   =  "distributeData";
    public static final String HANDLEISSUE_TOPIC = "HandleIssue_Send";
    public static final String CONTROLSWITCHDEFINITION_TOPIC = "ControlSwitchDefinition_Send";
    public static final String CONTROLSWITCHSORT_TOPIC = "ControlSwitchSort_Send";
    public static final String CONTROLSWITCHSTATUS_TOPIC = "ControlSwitchStatus_Send";
    public static final String CONTROLSWITCHSTATUSSORT_TOPIC = "ControlSwitchStatusSort_Send";
    public static final String ADDPOLYGONAREA_TOPIC = "AddPolygonArea_Send";
    public static final String DELETEPOLYGONAREA_TOPIC = "DeletePolygonArea_Send";
    public static final String SORTPOLYGONAREA_TOPIC = "SortPolygonArea_Send";
    public static final String ADDROUTE_TOPIC = "AddRoute_Send";
    public static final String DELETEROUTE_TOPIC = "DeleteRoute_Send";
    public static final String SORTROUTE_TOPIC = "SortRoute_Send";
    public static final String LIMITLEFTISSUE_TOPIC = "LimitLeftIssue_Send";
    public static final String LIMITSPEEDISSUE_TOPIC = "LimitSpeedIssue_Send";
    public static final String LOCKCAR_TOPIC = "LockCar_Send";
    public static final String RemoteUpgrade_topic="RemoteUpgrade_send";
    public static final String DeviceVersionQuery_topic="DeviceVersionQuery_Send";
    public static final String FaceInfo_topic="DriverFace_Send";
    public static final String DriverContrastResult_topic="DriverContrastResult_Send";
    public static final String DeviceInput_topic="DeviceInput_Send";
    public static final String DriverInformationInquiry_topic="DriverMsgSort_Send";
    public static final String QUERYSERVERTIMERESPONSE_TOPIC= "QueryServerTimeResponse_send";
    public static final String QUERYAREAORLINEDATA_TOPIC="QueryAreaOrLineData_send";
    public static final String REALTIMEMEDIAUPLOADREQ_SEND="RealtimeMediaUploadReq_Send";

    public static final String TERMINALAUTHENTICATION = "terminalAuthentication";//车辆注册信息消息

    public static final String UP_EXG_MSG_SAFETY_TERMINAL = "UP_EXG_MSG_SAFETY_TERMINAL";
    public static final String UP_WARN_MSG_INFO_EX = "UP_WARN_MSG_INFO_EX";
    public static final String UP_WARN_MSG_OPERATION_INFO_EX = "UP_WARN_MSG_OPERATION_INFO_EX";
    public static final String distributeToJT809 = "distributeToJT809";//平台置809的指令消息
    public static final String Text_Send="Text_Send";   //文本信息下发
    public static final String TakePhotoRightAway_Send="TakePhotoRightAway_Send";   //摄像头立即拍摄命令

    @Autowired
    KafkaProducerConfig kafkaProducerConfig;

    @Autowired
    private NettyClientConfig nettyClientConfig;

    @Autowired
    DistributeRepImpl distributeRep;

    private SimpleDateFormat formatter;

    @ApiOperation("指令下发")
    @CrossOrigin //允许跨域认证
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
            @ApiImplicitParam(name = "content", value = "终端设备id", dataType = "string", paramType = "query",required = true),
    })
    @PostMapping(value = "/{controllerPath}/distributeAll")

    public @ResponseBody R distributeAll(@RequestBody DistributeTotality distributeTotality) throws Exception{
        StatusResult result = null;
        String sqlID = null;
        MapUtil mapUtil=new MapUtil();
        DistributeEntity distributeEntity = null;
        try {
            logger.info("distributeUpgrade 接口调用id：{}", distributeTotality.getId());
            logger.info("distributeUpgrade 接口调用content：{}", distributeTotality.getContent());
            distributeEntity = GsonUtils.getObjectFromJson(distributeTotality.getContent(), DistributeEntity.class);

            distributeEntity.msgId = Jt808MsgIdTopicDic.getMsgId(distributeEntity.distributeMsgTopic);

            sqlID = distributeTotality.getId().toString();
            distributeRep.addRequestData(sqlID,distributeEntity);
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, distributeTotality.getContent());
            logger.info("sqlID:---" + sqlID );
            result = distributeRep.getDistributeResponse(sqlID);
            Map<String, Object> map2 =mapUtil.UpdateDatabases(result);
            map2.put("id", sqlID);
            String param1 = JSONObject.toJSONString(map2);
            HttpUtil.send(gtApiConfig.getOrderSendRecordUpdateUrl(),param1, "UTF-8");
            logger.info("distributeAll 接口调用成功");
            return R.ok();
        }catch (Exception e){

            result = new StatusResult(OrderSendStatus.设备应答超时, distributeEntity);
            Map<String, Object> map2 =mapUtil.UpdateDatabases(result);
            map2.put("id", sqlID);
            String param1 = JSONObject.toJSONString(map2);
            HttpUtil.send(gtApiConfig.getOrderSendRecordUpdateUrl(),param1, "UTF-8");
            logger.error("distributeAll 接口异常：{}", e);
            return R.error(e.toString());
        }
    }
//
    @ApiOperation("指令下发")
    @CrossOrigin //允许跨域认证
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
            @ApiImplicitParam(name = "content", value = "终端设备id", dataType = "string", paramType = "query",required = true),
    })
    @PostMapping(value = "/{controllerPath}/distributeUpgrade")

    public @ResponseBody R distributeUpgrade(@RequestBody DistributeTotality distributeTotality) throws Exception{
        StatusResult result = null;
        String sqlID = null;
        MapUtil mapUtil=new MapUtil();
        DistributeEntity distributeEntity = null;
        try {
            logger.info("distributeUpgrade 接口调用id：{}", distributeTotality.getId());
            logger.info("distributeUpgrade 接口调用content：{}", distributeTotality.getContent());
            distributeEntity = GsonUtils.getObjectFromJson(distributeTotality.getContent(), DistributeEntity.class);

            distributeEntity.msgId = Jt808MsgIdTopicDic.getMsgId(distributeEntity.distributeMsgTopic);

            sqlID = distributeTotality.getId().toString();
            distributeRep.addRequestData(sqlID,distributeEntity);
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, distributeTotality.getContent());
            JSONObject json = JSONObject.parseObject(distributeTotality.getContent());
            String vNumber = String.valueOf(json.get("vNumber"));
            String devNo = String.valueOf(json.get("devNo"));

            result = distributeRep.getDistributeResponse(sqlID);
            Map<String, Object> map2 =mapUtil.UpdateUpgradeDatabases(result,vNumber,devNo);
            map2.put("id", sqlID);
            String param1 = JSONObject.toJSONString(map2);
            HttpUtil.send(gtApiConfig.getOrderSendRecordUpdateUrl(),param1, "UTF-8");
            logger.info("distributeAll 接口调用成功");
            return R.ok();
        }catch (Exception e){
            result = new StatusResult(OrderSendStatus.设备应答超时, distributeEntity);
            Map<String, Object> map2 =mapUtil.UpdateDatabases(result);
            map2.put("id", sqlID);
            String param1 = JSONObject.toJSONString(map2);
            HttpUtil.send(gtApiConfig.getOrderSendRecordUpdateUrl(),param1, "UTF-8");
            logger.error("distributeAll 接口异常：{}", e.getMessage());
            return R.error();
        }
    }


    @ApiOperation("809与前端对接接口")
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/distribute809")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
    })
    public @ResponseBody R distribute809(String distribute809Content) throws Exception{
//        kafkaProducerConfig.kafkaTemplate().send(distributeToJT809, map.get("distribute809Content").toString());
        R r = new R();
        try {
            kafkaProducerConfig.kafkaTemplate().send(distributeToJT809, distribute809Content);
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    @ApiOperation("指令下发")
    @CrossOrigin //允许跨域认证
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
    })
    @PostMapping(value = "/{controllerPath}/distributeInner")

    public @ResponseBody StatusResult distributeInner(String distributeContent) {
        try {
                logger.info("distributeInner 接口调用：{}", distributeContent);
                DistributeEntity distributeEntity = GsonUtils.getObjectFromJson(distributeContent, DistributeEntity.class);
                kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, distributeContent);
                logger.info("distributeInner 接口调用成功");
                return new StatusResult(OrderSendStatus.发送成功, null);
            } catch (Exception e) {
                logger.error("distributeInner 接口异常：{}", e.getMessage());
                return new StatusResult(OrderSendStatus.消息处理异常, e.getMessage());
            }
        }

    @ApiOperation("将车辆注册数据推送到kafka")
    @CrossOrigin //允许跨域认证
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
    })
    @PostMapping(value = "/{controllerPath}/VehicleRegistration")
    public @ResponseBody R VehicleRegistration(@RequestBody Map<String, Object> map) {
        R r = new R();
        try {
            List<LinkedHashMap> list = (List<LinkedHashMap>) map.get("list");
            for (LinkedHashMap object : list) {
                String jsonObject = JSON.toJSONString(object);
                VehicleRegistrationInformation vehicleRegistrationInformation = JSON.parseObject(jsonObject, VehicleRegistrationInformation.class);
                kafkaProducerConfig.kafkaTemplate().send(Jt808DistributeMsgTopic.VehicleRegistrationInfor, vehicleRegistrationInformation.toJSONString().toString());
            }
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    @ApiOperation("文本信息下发")
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/TextSend")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
    })
    public @ResponseBody R TextSend(@RequestBody Map<String, Object> textDataMap) throws Exception{

        R r = new R();
        try {
//            Text text = JSON.parseObject(JSON.toJSONString(textDataMap.get("data")),Text.class);
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,JSON.toJSONString(textDataMap.get("data")));

            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    @ApiOperation("拍照指令")
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/TakePhoto")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "controllerPath", paramType = "path", allowableValues = "web", required = true),
    })
    public @ResponseBody R TakePhoto(@RequestBody Map<String, Object> TakePhotoData) throws Exception{
        R r = new R();

        List<Map<String, Object>> list = (List<Map<String, Object>>) TakePhotoData.get("list");
        for (Map<String, Object> map:list) {
//            DistributeTotality distributeTotality = new DistributeTotality();
//            distributeTotality.setContent(JSON.toJSONString(map));
//            DistributeEntity data =  GsonUtils.getObjectFromJson(distributeTotality.getContent(), DistributeEntity.class);
//            data.setHostName("192.168.2.237");
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,JSON.toJSONString(map));
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }


    /**
     * 下发处置证消息指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/handleIssue")
    public @ResponseBody R handleIssue(HttpServletRequest request) throws Exception{
        formatter = new SimpleDateFormat( "yyMMddHHmmss");
        R r = new R();
        HandleIssue handleIssue = new HandleIssue();
        handleIssue.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = handleIssue.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            handleIssue.devNo = deviceNumStrArray[i];
            handleIssue.messageId = (int)Long.parseLong("8620",16);
            handleIssue.id = Integer.valueOf(request.getParameter("id"));
            handleIssue.operation = Integer.valueOf(request.getParameter("operation"));
            handleIssue.businessValue = Integer.valueOf(request.getParameter("businessValue"));
            handleIssue.startTime = formatter.parse(request.getParameter("startTime"));
            handleIssue.endTime = formatter.parse(request.getParameter("endTime"));
            handleIssue.content = request.getParameter("content");
            handleIssue.distributeMsgTopic = HANDLEISSUE_TOPIC;
            handleIssue.msgId = (int)Long.parseLong("8620",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            handleIssue.requestId = id + "";
            handleIssue.userId = "123456";
            handleIssue.userName = "wupeng";
            handleIssue.distributeTime = new Date();
            handleIssue.serialNo = 123456;

            //下发处置证消息
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,handleIssue.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发管控开关定义指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/ControlSwitchDefinition")
    public @ResponseBody R ControlSwitchDefinition(HttpServletRequest request) throws Exception{
        R r = new R();
        ControlSwitchDefinition controlSwitchDefinition = new ControlSwitchDefinition();
        controlSwitchDefinition.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = controlSwitchDefinition.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            controlSwitchDefinition.devNo = deviceNumStrArray[i];
            controlSwitchDefinition.messageId = (int)Long.parseLong("F114",16);
            controlSwitchDefinition.id = Integer.parseInt(request.getParameter("id"));
            controlSwitchDefinition.liftSwitch = Integer.parseInt(request.getParameter("liftSwitch"));
            controlSwitchDefinition.speeding = Integer.parseInt(request.getParameter("speeding"));
            controlSwitchDefinition.beyondBoundsAlarm = Integer.parseInt(request.getParameter("beyondBoundsAlarm"));
            controlSwitchDefinition.uploadAlarm = Integer.parseInt(request.getParameter("uploadAlarm"));
            controlSwitchDefinition.unlicensedAlarm = Integer.parseInt(request.getParameter("unlicensedAlarm"));
            controlSwitchDefinition.driverAlarm = Integer.parseInt(request.getParameter("driverAlarm"));
            controlSwitchDefinition.breakAlarm = Integer.parseInt(request.getParameter("breakAlarm"));
            controlSwitchDefinition.keep = Integer.parseInt(request.getParameter("keep"));


            controlSwitchDefinition.distributeMsgTopic = CONTROLSWITCHDEFINITION_TOPIC;
            controlSwitchDefinition.msgId = (int)Long.parseLong("F114",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            controlSwitchDefinition.requestId = id + "";
            controlSwitchDefinition.userId = "123456";
            controlSwitchDefinition.userName = "wupeng";
            controlSwitchDefinition.distributeTime = new Date();
            controlSwitchDefinition.serialNo = 123456;

            //下发管控开关定义指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,controlSwitchDefinition.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发管控开关查询指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/ControlSwitchSort")
    public @ResponseBody R ControlSwitchSort(HttpServletRequest request) throws Exception{
        R r = new R();
        ControlSwitchSort controlSwitchSort = new ControlSwitchSort();
        controlSwitchSort.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = controlSwitchSort.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            controlSwitchSort.devNo = deviceNumStrArray[i];
            controlSwitchSort.distributeMsgTopic = CONTROLSWITCHSORT_TOPIC;
            controlSwitchSort.msgId = (int)Long.parseLong("F115",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            controlSwitchSort.requestId = id + "";
            controlSwitchSort.userId = "123456";
            controlSwitchSort.userName = "wupeng";
            controlSwitchSort.distributeTime = new Date();
            controlSwitchSort.serialNo = 123456;
            controlSwitchSort.response = false;

            //下发管控开关查询指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,controlSwitchSort.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }
    /*
     **服务器时间请求
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/QueryServerTimeResponse")
    public @ResponseBody R QueryServerTimeResponse(HttpServletRequest request) throws Exception{
        R r = new R();
        QueryServerTimeResponse queryServerTimeResponse = new QueryServerTimeResponse();
        queryServerTimeResponse.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = queryServerTimeResponse.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            queryServerTimeResponse.setServerTime(new Date());
            queryServerTimeResponse.devNo = deviceNumStrArray[i];
            queryServerTimeResponse.versionId=1;
            queryServerTimeResponse.distributeMsgTopic = QUERYSERVERTIMERESPONSE_TOPIC;
            queryServerTimeResponse.msgId = (int)Long.parseLong("8004",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            queryServerTimeResponse.requestId = id + "";
            queryServerTimeResponse.userId = "123456";
            queryServerTimeResponse.userName = "wupeng";
            queryServerTimeResponse.distributeTime = new Date();
            queryServerTimeResponse.serialNo = 123456;
            queryServerTimeResponse.response = false;
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,queryServerTimeResponse.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }
    /**
     * 下发管控开关状态控制指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/ControlSwitchStatus")
    public @ResponseBody R ControlSwitchStatus(HttpServletRequest request) throws Exception{
        R r = new R();
        ControlSwitchStatus controlSwitchStatus = new ControlSwitchStatus();
        controlSwitchStatus.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = controlSwitchStatus.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            controlSwitchStatus.devNo = deviceNumStrArray[i];
            controlSwitchStatus.liftSwitch = Integer.parseInt(request.getParameter("liftSwitch"));
            controlSwitchStatus.speedSwitch = Integer.parseInt(request.getParameter("speedSwitch"));
            controlSwitchStatus.lockCarSwitch = Integer.parseInt(request.getParameter("lockCarSwitch"));

            controlSwitchStatus.distributeMsgTopic = CONTROLSWITCHSTATUS_TOPIC;
            controlSwitchStatus.msgId = (int)Long.parseLong("F116",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            controlSwitchStatus.requestId = id + "";
            controlSwitchStatus.userId = "123456";
            controlSwitchStatus.userName = "wupeng";
            controlSwitchStatus.distributeTime = new Date();
            controlSwitchStatus.serialNo = 123456;

            //下发管控开关状态控制指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,controlSwitchStatus.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发管控开关状态查询指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/ControlSwitchStatusSort")
    public @ResponseBody R ControlSwitchStatusSort(HttpServletRequest request) throws Exception{
        R r = new R();
        ControlSwitchStatusSort controlSwitchStatusSort = new ControlSwitchStatusSort();
        controlSwitchStatusSort.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = controlSwitchStatusSort.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            controlSwitchStatusSort.devNo = deviceNumStrArray[i];
            controlSwitchStatusSort.distributeMsgTopic = CONTROLSWITCHSTATUSSORT_TOPIC;
            controlSwitchStatusSort.msgId = (int)Long.parseLong("F117",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            controlSwitchStatusSort.requestId = id + "";
            controlSwitchStatusSort.userId = "123456";
            controlSwitchStatusSort.userName = "wupeng";
            controlSwitchStatusSort.distributeTime = new Date();
            controlSwitchStatusSort.serialNo = 123456;


            //下发管控开关状态查询指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,controlSwitchStatusSort.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发新增多边形区域指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/AddPolygonArea")
    public @ResponseBody R AddPolygonArea(HttpServletRequest request) throws Exception{
        R r = new R();
        formatter = new SimpleDateFormat("yyMMddHHmmss");
        PolygonAreaInfo polygonAreaInfo = new PolygonAreaInfo();
        polygonAreaInfo.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = polygonAreaInfo.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            polygonAreaInfo.devNo = deviceNumStrArray[i];
            polygonAreaInfo.flag = Integer.parseInt(request.getParameter("flag"));
            polygonAreaInfo.count = Integer.parseInt(request.getParameter("count"));
            polygonAreaInfo.signId = Integer.parseInt(request.getParameter("signId"));
            polygonAreaInfo.areaProperty = Integer.parseInt(request.getParameter("areaProperty"));
            polygonAreaInfo.startTime = formatter.parse(request.getParameter("startTime"));
            polygonAreaInfo.endTime =  formatter.parse(request.getParameter("endTime"));
            polygonAreaInfo.businessValue = Integer.parseInt(request.getParameter("businessValue"));
            polygonAreaInfo.point = Integer.parseInt(request.getParameter("point"));
            polygonAreaInfo.Lng = Double.parseDouble((request.getParameter("Lng")));
            polygonAreaInfo.Lat = Double.parseDouble((request.getParameter("Lat")));


            polygonAreaInfo.distributeMsgTopic = ADDPOLYGONAREA_TOPIC;
            polygonAreaInfo.msgId = (int)Long.parseLong("860D",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            polygonAreaInfo.requestId = id + "";
            polygonAreaInfo.userId = "123456";
            polygonAreaInfo.userName = "wupeng";
            polygonAreaInfo.distributeTime = new Date();
            polygonAreaInfo.serialNo = 123456;

            //下发新增多边形区域指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,polygonAreaInfo.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发删除多边形区域指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/DeletePolygonArea")
    public @ResponseBody R DeletePolygonArea(HttpServletRequest request) throws Exception{
        R r = new R();
        DeletePolygonArea deletePolygonArea = new DeletePolygonArea();
        deletePolygonArea.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = deletePolygonArea.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            deletePolygonArea.devNo = deviceNumStrArray[i];
            deletePolygonArea.deleteCount = request.getParameter("signIds").length();
            deletePolygonArea.signIds = Collections.singletonList(Integer.parseInt(request.getParameter("signIds")));

            deletePolygonArea.distributeMsgTopic = DELETEPOLYGONAREA_TOPIC;
            deletePolygonArea.msgId = (int)Long.parseLong("860E",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            deletePolygonArea.requestId = id + "";
            deletePolygonArea.userId = "123456";
            deletePolygonArea.userName = "wupeng";
            deletePolygonArea.distributeTime = new Date();
            deletePolygonArea.serialNo = 123456;

            //下发删除多边形区域指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,deletePolygonArea.toJSONString().toString());
        }

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     * 下发查询多边型区域指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/PolygonAreaSort")
    public @ResponseBody R PolygonAreaSort(HttpServletRequest request) throws Exception{
        R r = new R();
        PolygonAreaSort polygonAreaSort = new PolygonAreaSort();
        polygonAreaSort.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = polygonAreaSort.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            polygonAreaSort.devNo = deviceNumStrArray[i];
            polygonAreaSort.distributeMsgTopic = SORTPOLYGONAREA_TOPIC;
            polygonAreaSort.msgId = (int)Long.parseLong("860F",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            polygonAreaSort.requestId = id + "";
            polygonAreaSort.userId = "123456";
            polygonAreaSort.userName = "wupeng";
            polygonAreaSort.distributeTime = new Date();
            polygonAreaSort.serialNo = 123456;

            //下发查询多边型区域指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,polygonAreaSort.toJSONString().toString());
        }


        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发新增线路指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/AddRoute")
    public @ResponseBody R AddRoute(HttpServletRequest request) throws Exception{
        R r = new R();
        AddRoute addRoute = new AddRoute();
        addRoute.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = addRoute.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            addRoute.devNo = deviceNumStrArray[i];
            addRoute.flag = Integer.parseInt(request.getParameter("flag"));
            addRoute.signId = Integer.parseInt(request.getParameter("signId"));
            addRoute.routeWidth = Integer.parseInt(request.getParameter("routeWidth"));
            addRoute.businessValue = Integer.parseInt(request.getParameter("businessValue"));
            addRoute.point = Integer.parseInt(request.getParameter("point"));
            addRoute.Lng = Double.parseDouble((request.getParameter("Lng")));
            addRoute.Lat = Double.parseDouble(request.getParameter("Lat"));

            addRoute.distributeMsgTopic = ADDROUTE_TOPIC;
            addRoute.msgId = (int)Long.parseLong("8610",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            addRoute.requestId = id + "";
            addRoute.userId = "123456";
            addRoute.userName = "wupeng";
            addRoute.distributeTime = new Date();
            addRoute.serialNo = 123456;

            //下发新增线路指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,addRoute.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发删除清空线路指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/DeleteRoute")
    public @ResponseBody R DeleteRoute(HttpServletRequest request) throws Exception{
        R r = new R();

        DeleteRoute deleteRoute = new DeleteRoute();
        deleteRoute.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = deleteRoute.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            deleteRoute.devNo = deviceNumStrArray[i];
            deleteRoute.deleteCount = request.getParameter("deleteCount").length();
            deleteRoute.signIds = Collections.singletonList(Integer.parseInt(request.getParameter("signIds")));

            deleteRoute.distributeMsgTopic = DELETEROUTE_TOPIC;
            deleteRoute.msgId = (int)Long.parseLong("8611",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            deleteRoute.requestId = id + "";
            deleteRoute.userId = "123456";
            deleteRoute.userName = "wupeng";
            deleteRoute.distributeTime = new Date();
            deleteRoute.serialNo = 123456;

            //下发删除清空线路指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,deleteRoute.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     *下发查询线路指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/RouteSort")
    public @ResponseBody R RouteSort(HttpServletRequest request) throws Exception{
        R r = new R();
        RouteSort routeSort = new RouteSort();
        routeSort.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = routeSort.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            routeSort.devNo = deviceNumStrArray[i];
            routeSort.distributeMsgTopic = SORTROUTE_TOPIC;
            routeSort.msgId = (int)Long.parseLong("8612",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            routeSort.requestId = id + "";
            routeSort.userId = "123456";
            routeSort.userName = "wupeng";
            routeSort.distributeTime = new Date();
            routeSort.serialNo = 123456;
            //下发查询线路指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,routeSort.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     * 下发限举指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/LimitLeftIssue")
    public @ResponseBody R LimitLeftIssue(HttpServletRequest request) throws Exception{
        R r = new R();
        LimitLeftIssue limitLeftIssue = new LimitLeftIssue();
        limitLeftIssue.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = limitLeftIssue.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            limitLeftIssue.devNo = deviceNumStrArray[i];
            limitLeftIssue.liftType = Integer.parseInt(request.getParameter("liftType"));
            limitLeftIssue.distributeMsgTopic = LIMITLEFTISSUE_TOPIC;
            limitLeftIssue.msgId = (int)Long.parseLong("8622",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            limitLeftIssue.requestId = id + "";
            limitLeftIssue.userId = "123456";
            limitLeftIssue.userName = "wupeng";
            limitLeftIssue.distributeTime = new Date();
            limitLeftIssue.serialNo = 123456;

            //下发限举指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,limitLeftIssue.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     * 下发限速指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/LimitSpeedIssue")
    public @ResponseBody R LimitSpeedIssue(HttpServletRequest request) throws Exception{
        R r = new R();
        LimitSpeedIssue limitSpeedIssue = new LimitSpeedIssue();
        limitSpeedIssue.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = limitSpeedIssue.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            limitSpeedIssue.speedType = Integer.parseInt(request.getParameter("speedType"));
            limitSpeedIssue.speedValue = Integer.parseInt(request.getParameter("speedValue"));

            limitSpeedIssue.distributeMsgTopic = LIMITSPEEDISSUE_TOPIC;
            limitSpeedIssue.msgId = (int)Long.parseLong("8623",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            limitSpeedIssue.requestId = id + "";
            limitSpeedIssue.userId = "123456";
            limitSpeedIssue.userName = "wupeng";
            limitSpeedIssue.distributeTime = new Date();
            limitSpeedIssue.serialNo = 123456;

            //下发限速指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,limitSpeedIssue.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     * 下发锁车指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/LockCar")
    public @ResponseBody R LockCar(HttpServletRequest request) throws Exception{
        R r = new R();
        LockCar lockCar = new LockCar();
        lockCar.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = lockCar.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            lockCar.devNo = deviceNumStrArray[i];
            lockCar.command = Integer.parseInt(request.getParameter("command"));
            lockCar.distributeMsgTopic = LOCKCAR_TOPIC;
            lockCar.msgId = (int)Long.parseLong("F110",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            lockCar.requestId = id + "";
            lockCar.userId = "123456";
            lockCar.userName = "wupeng";
            lockCar.distributeTime = new Date();
            lockCar.serialNo = 123456;

            //下发锁车指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,lockCar.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }

    }

    /**
     * 下发远程升级指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/remoteUpgrade")
    public @ResponseBody
    R remoteUpgrade(HttpServletRequest request) throws Exception {
        formatter = new SimpleDateFormat( "yyMMddHHmmss");
        R r = new R();
        RemoteUpgrade remoteUpgrade = new RemoteUpgrade();
        remoteUpgrade.upgradeType=Integer.valueOf(request.getParameter("upgradeType"));
        remoteUpgrade.vNumber=request.getParameter("vNumber");
        remoteUpgrade.synchronizationTime=formatter.parse(request.getParameter("synchronizationTime"));
        remoteUpgrade.ftpipAddress=request.getParameter("ftpipAddress");
        remoteUpgrade.port=Integer.valueOf(request.getParameter("port"));
        remoteUpgrade.ftpVersionFileAddress=request.getParameter("ftpVersionFileAddress");
        remoteUpgrade.fileName=request.getParameter("fileName");
        remoteUpgrade.ftpAccount=request.getParameter("ftpAccount");
        remoteUpgrade.ftpPassword=request.getParameter("ftpPassword");
        remoteUpgrade.devNo = request.getParameter("devNo");
        remoteUpgrade.distributeMsgTopic = RemoteUpgrade_topic;
        remoteUpgrade.msgId = (int) Long.parseLong("8901", 16);
        long id = SnowFlakeIDGenerator.getInstance().nextId();
        remoteUpgrade.requestId = id + "";
        remoteUpgrade.userId = "123456";
        remoteUpgrade.userName = "wupeng";
        remoteUpgrade.distributeTime = new Date();
        remoteUpgrade.serialNo = 123456;

        //下发远程升级指令
        kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, remoteUpgrade.toJSONString().toString());
        try {
            r.put("code", "0");
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", "1");
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发设备版本查询指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/deviceVersionQuery")
    public @ResponseBody
    R deviceVersionQuery(HttpServletRequest request) throws Exception {
        R r = new R();
        DeviceVersionQuery deviceVersionQuery = new DeviceVersionQuery();
        deviceVersionQuery.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = deviceVersionQuery.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            deviceVersionQuery.deviceType=Integer.valueOf(request.getParameter("deviceType"));
            deviceVersionQuery.distributeMsgTopic = DeviceVersionQuery_topic;
            deviceVersionQuery.msgId = (int) Long.parseLong("8902", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            deviceVersionQuery.requestId = id + "";
            deviceVersionQuery.userId = "123456";
            deviceVersionQuery.userName = "wupeng";
            deviceVersionQuery.distributeTime = new Date();
            deviceVersionQuery.serialNo = 123456;

            //设备版本查询
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, deviceVersionQuery.toJSONString().toString());
        }

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发驾驶员人脸同步指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/faceInfo")
    public @ResponseBody
    R faceInfo(HttpServletRequest request) throws Exception {
        R r = new R();
        FaceInfo faceInfo = new FaceInfo();
        faceInfo.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = faceInfo.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            faceInfo.devNo = deviceNumStrArray[i];
            faceInfo.Type=Integer.valueOf(request.getParameter("Type"));
            faceInfo.faceNumber=Integer.valueOf(request.getParameter("faceNumber"));
            faceInfo.driverId=request.getParameter("driverId");
            faceInfo.jobSeniorityCard=request.getParameter("jobSeniorityCard");
            faceInfo.driverName=request.getParameter("driverName");
            faceInfo.facePictureAgreement=Integer.valueOf(request.getParameter("facePictureAgreement"));
            faceInfo.facePictureId=request.getParameter("facePictureId");
            faceInfo.facePictureUrl=request.getParameter("facePictureUrl");

            faceInfo.distributeMsgTopic = FaceInfo_topic;
            faceInfo.msgId = (int) Long.parseLong("8E21", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            faceInfo.requestId = id + "";
            faceInfo.userId = "123456";
            faceInfo.userName = "wupeng";
            faceInfo.distributeTime = new Date();
            faceInfo.serialNo = 123456;

            //驾驶员人脸同步
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, faceInfo.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发驾驶员对比结果上报指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/driverContrastResult")
    public @ResponseBody
    R driverContrastResult(HttpServletRequest request) throws Exception {
        R r = new R();
        DriverContrastResult devNo=new DriverContrastResult();
        devNo.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = devNo.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            devNo.devNo = deviceNumStrArray[i];
            devNo.orgSerialNum=Integer.valueOf(request.getParameter("orgSerialNum"));
            devNo.packageCount=Integer.valueOf(request.getParameter("packageCount"));
            devNo.packageId=Byte.valueOf(request.getParameter("packageId"));

            devNo.distributeMsgTopic = DriverContrastResult_topic;
            devNo.msgId = (int) Long.parseLong("8E10", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            devNo.requestId = id + "";
            devNo.userId = "123456";
            devNo.userName = "wupeng";
            devNo.distributeTime = new Date();
            devNo.serialNo = 123456;
            //驾驶员对比结果上报
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, devNo.toJSONString().toString());
        }

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发设备录入驾驶员信息上报指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/deviceInput")
    public @ResponseBody
    R deviceInput(HttpServletRequest request) throws Exception {
        R r = new R();
        DeviceInput deviceInput=new DeviceInput();
        deviceInput.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = deviceInput.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            deviceInput.devNo = deviceNumStrArray[i];
            deviceInput.orgSerialNum=Integer.valueOf(request.getParameter("orgSerialNum"));
            deviceInput.packageCount=Integer.valueOf(request.getParameter("packageCount"));
            deviceInput.packageId=Byte.valueOf(request.getParameter("packageId"));

            deviceInput.distributeMsgTopic = DeviceInput_topic;
            deviceInput.msgId = (int) Long.parseLong("8E13", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            deviceInput.requestId = id + "";
            deviceInput.userId = "123456";
            deviceInput.userName = "wupeng";
            deviceInput.distributeTime = new Date();
            deviceInput.serialNo = 123456;
            //设备录入驾驶员信息上报
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, deviceInput.toJSONString().toString());
        }

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发驾驶员信息查询指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/driverInformationInquiry")
    public @ResponseBody
    R driverInformationInquiry(HttpServletRequest request) throws Exception {
        R r = new R();
        DriverInformationInquiry driverInformationInquiry=new DriverInformationInquiry();
        driverInformationInquiry.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = driverInformationInquiry.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            driverInformationInquiry.devNo = deviceNumStrArray[i];
            driverInformationInquiry.distributeMsgTopic = DriverInformationInquiry_topic;
            driverInformationInquiry.msgId = (int) Long.parseLong("8E12", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            driverInformationInquiry.requestId = id + "";
            driverInformationInquiry.userId = "123456";
            driverInformationInquiry.userName = "wupeng";
            driverInformationInquiry.distributeTime = new Date();
            driverInformationInquiry.serialNo = 123456;
            //驾驶员信息查询
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, driverInformationInquiry.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/QueryAreaOrLineData")
    public @ResponseBody R QueryAreaOrLineData(HttpServletRequest request) throws Exception{
        R r = new R();
        QueryAreaOrLineData queryAreaOrLineData=new QueryAreaOrLineData();
        List<Integer> list=new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        list.add(3);
        queryAreaOrLineData.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = queryAreaOrLineData.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            queryAreaOrLineData.setQueryType(1);
            queryAreaOrLineData.setLineIds(list);
            queryAreaOrLineData.devNo = deviceNumStrArray[i];
            queryAreaOrLineData.distributeMsgTopic = QUERYAREAORLINEDATA_TOPIC;
//            queryAreaOrLineData.versionId = 1;
            queryAreaOrLineData.msgId = (int)Long.parseLong("8608",16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            queryAreaOrLineData.requestId = id + "";
            queryAreaOrLineData.userId = "123456";
            queryAreaOrLineData.userName = "wupeng";
            queryAreaOrLineData.distributeTime = new Date();
            queryAreaOrLineData.serialNo = 123456;
            queryAreaOrLineData.response = false;
            //下发管控开关查询指令
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA,queryAreaOrLineData.toJSONString().toString());
        }
        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 下发实时音视频传输控制指令
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/RealtimeMediaUploadReq")
    public @ResponseBody
    R RealtimeMediaUploadReq(HttpServletRequest request) throws Exception {
        R r = new R();
        RealtimeMediaUploadReq realtimeMediaUploadReq=new RealtimeMediaUploadReq();
        realtimeMediaUploadReq.devNo = request.getParameter("devNo");
        String[] deviceNumStrArray = realtimeMediaUploadReq.devNo.split(",");
        for (int i = 0; i<deviceNumStrArray.length; i++){
            realtimeMediaUploadReq.devNo = deviceNumStrArray[i];
            realtimeMediaUploadReq.ip=String.valueOf(request.getParameter("ip"));
            realtimeMediaUploadReq.tcpPort=Integer.valueOf(request.getParameter("tcpPort"));
            realtimeMediaUploadReq.udpPort=Integer.valueOf(request.getParameter("udpPort"));
            realtimeMediaUploadReq.chanelId=Integer.valueOf(request.getParameter("chanelId"));
            realtimeMediaUploadReq.mediaType=Integer.valueOf(request.getParameter("mediaType"));
            realtimeMediaUploadReq.codeType=Integer.valueOf(request.getParameter("codeType"));

            realtimeMediaUploadReq.distributeMsgTopic = REALTIMEMEDIAUPLOADREQ_SEND;
            realtimeMediaUploadReq.msgId = (int) Long.parseLong("9101", 16);
            long id = SnowFlakeIDGenerator.getInstance().nextId();
            realtimeMediaUploadReq.requestId = id + "";
            realtimeMediaUploadReq.userId = "123456";
            realtimeMediaUploadReq.userName = "wupeng";
            realtimeMediaUploadReq.distributeTime = new Date();
            realtimeMediaUploadReq.serialNo = 123456;
            //实时音视频传输控制
            kafkaProducerConfig.kafkaTemplate().send(TOPIC_DISTRIBUTE_DATA, realtimeMediaUploadReq.toJSONString().toString());
        }

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    /**
     * 车辆注册信息消息
     * @param request
     * @return
     * @throws Exception
     */
    @CrossOrigin //允许跨域认证
    @PostMapping(value = "/{controllerPath}/UpExgMsgRegister")
    public @ResponseBody
    R UpExgMsgRegister(HttpServletRequest request)throws Exception{
        R r = new R();
        UpExgMsgRegister upExgMsgRegister = new UpExgMsgRegister();
        BasicVehicleInfo basicVehicleInfo = new BasicVehicleInfo();
        basicVehicleInfo.vehicleNo = request.getParameter("vehicleNo");
        basicVehicleInfo.vehicleColor = Integer.valueOf(request.getParameter("vehicleColor"));
        upExgMsgRegister.basicVehicleInfo = basicVehicleInfo;
        upExgMsgRegister.producerId = request.getParameter("producerId");
        upExgMsgRegister.terminalModelType= request.getParameter("terminalModelType");
        upExgMsgRegister.terminalId = request.getParameter("terminalId");
        upExgMsgRegister.terminalSimCode = request.getParameter("terminalSimCode");
        upExgMsgRegister.PlatformId = nettyClientConfig.getPlatformId();

        upExgMsgRegister.msgId = (int) Long.parseLong("1201", 16);
        upExgMsgRegister.userId = "123456";
        upExgMsgRegister.userName = "aaa";
        upExgMsgRegister.distributeTime = new Date();

        kafkaProducerConfig.kafkaTemplate().send(TERMINALAUTHENTICATION, upExgMsgRegister.toJSONString().toString());

        try {
            r.put("code", 0);
            r.put("msg", "success");
            return r;
        } catch (Exception e) {
            r.put("code", 1);
            r.put("msg", e.getMessage());
            return r;
        } finally {
            return r;
        }
    }

    








}
